import time
import sys
import pp

def copy(filename, x):
    source = open(filename)
    contents = source.read()
    source.close()

    dest = open('temp/%d' % x, 'w')
    dest.write(contents)
    dest.close()

if len(sys.argv) > 1:
    ncpus = int(sys.argv[1])
    # Creates jobserver with ncpus workers
    job_server = pp.Server(ncpus)
else:
    # Creates jobserver with automatically detected number of workers
    job_server = pp.Server()

print "Starting pp with", job_server.get_ncpus(), "workers"

# The file to be copied from
filename = ''

start = time.time()

for x in xrange(0,1000):
    job_server.submit(copy, (filename,x))

job_server.wait()

print time.time() - start

job_server.print_stats()
